/**
 * @author smy
 *
 */
public class ObtainingDigitK {
	public static void main(String[] args) {
		System.out.println(minNumberToAdd("899",1));
	}
	public static int minNumberToAdd(String originalNumber, int k) {
		int length=originalNumber.length();
		char [] orig=originalNumber.toCharArray();
		for(int i=0;i<length;i++)
		if(orig[i]=='0'+k)return 0;
		if(orig[length-1]=='9' && length==1 && k==1)return 1;
		if(orig[length-1]=='8' && length==1 && k==1)return 2;
		if(orig[length-1]=='7' && length==1 && k==1)return 3;
		if(orig[length-1]=='6' && length==1 && k==1)return 4;
		if(orig[length-1]=='5' && length==1 && k==1)return 5;
		if(orig[length-1]=='4' && length==1 && k==1)return 6;
		if(orig[length-1]=='3' && length==1 && k==1)return 7;
		if(orig[length-1]=='2' && length==1 && k==1)return 8;
		int result=0;
		int flag1=0;
		while(true){
		    result++;
		    flag1=0;
			if(orig[length-1]=='9'){orig[length-1]='0';flag1=1;}
			else orig[length-1]++;
			if(orig[length-1]=='0'+k)return result;
			for(int i=length-2;i>=0;i--){
				if(orig[i+1]=='0' && orig[i]!='9' && flag1==1){orig[i]++;flag1=0;}
				else if(orig[i+1]=='0' && orig[i]=='9' && flag1==1){orig[i]='0';}
				if(i==0 && orig[i]=='0' && k==1)return result;
				if(orig[i]=='0'+k)return result;
			}
		}
	}
}
